package filters;

import interfaces.IMap;

public class EmbossFilter implements IFilter
{
	float FMapH[][];
	float FMapHR[][];
	float FMapV[][];
	float FMapVR[][];
    //===========================================================================
    public EmbossFilter()
    {
        FMapH = new float[3] [3];
        FMapH[0] [0] = 2;
        FMapH[1] [0] = 0;
        FMapH[2] [0] = 2;

        FMapH[0] [1] = 0;
        FMapH[1] [1] = 0;
        FMapH[2] [1] = 0;

        FMapH[0] [2] = -2;
        FMapH[1] [2] = 0;
        FMapH[2] [2] = -2;
    }
    //===========================================================================
    public int ApplyFilter(int Px,int Py, IMap map)
    {
    	int sum=0;
        
        for (int y = -1; y < 2; y++)
            for (int x = -1; x < 2; x++)
            {
            	int xf=x + 1;
            	int yf=y + 1;
            	float C = map.Get(Px + x,Py + y);
            	sum += (int)(C * FMapH[xf] [yf]);
            	
            }
        //sum=sum/;
        
        if (sum > 255)
            return (int)255;
        if (sum < 0)
            return (int)0;
        return (int)sum;
    }
    //===========================================================================

}
